package Circuit;

import java.util.Map;
import java.util.Vector;

import Basics.*;
import Derivation.*;

public class Circuit 
{
	Vector<Vector<CircuitNode>> levels = new Vector<Vector<CircuitNode>>();
	
	public Circuit (Map<Atom, Vector<Vector<Atom>>> provenance) 
	{
		this.BuildOneLevelBottomUp(provenance);
	}
	
	
	
	/*************************************************************************************************************/
	/** Title: BuildOneLevelBottomUp																					
	/** Description: Builds one level of the the circuit. used when running semiNaive									
	/*************************************************************************************************************/
	
	public void BuildOneLevelBottomUp (Map<Atom, Vector<Vector<Atom>>> provenance)
	{
		Vector<CircuitNode> curLevel = new Vector<CircuitNode>();
		levels.add(curLevel);
		for (Atom key : provenance.keySet()) 
		{
			CircuitNode derived = new CircuitNode(key, "AND");//temp
			curLevel.add(derived);
			for (Vector<Atom> prov : provenance.get(key)) 
			{
				for (Atom atom : prov) 
				{
					
					for (Vector<CircuitNode> vec : this.levels) 
					{
						
					}
				}
			}
		}
	}
	
	
	
	/*************************************************************************************************************/
	/** Title: BuildCircuitTopDown																					
	/** Description: Builds the circuit based on topDown provenance									
	/*************************************************************************************************************/
	
	/*public void BuildCircuitTopDown (Atom root, Map<Atom, Vector<Vector<Atom>>> provenance)
	{
		Vector<CircuitNode> curLevel = new Vector<CircuitNode>();
		Vector<Vector<Atom>> queue = new Vector<Vector<Atom>>();
		Vector<Atom> rootVec = new Vector<Atom> ();
		rootVec.add(root);
		queue.add(rootVec);
		
		while (false == queue.isEmpty())
		{
			Vector<Atom> curBody = queue.remove(0);
			for (Atom bodyAtom : curBody) 
			{
				for (Vector<Atom> body : provenance.get(bodyAtom)) 
				{
					CircuitNode connect = new CircuitNode("And");
					for (Atom atom : body) 
					{
						CircuitNode cn = new CircuitNode(atom, "Fact");
						cn.setParent(connect);
					}
					
					connect.setParent(bodyAtom);
				}
			}
			
		}
	}*/
}
